package com.csht.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.csht.model.CshtUser;
import com.csht.page.PagerModel;
import com.csht.page.SystemContext;
import com.csht.service.CshtMessageService;
import com.csht.vo.my.CshtMessageVo;

/**
 * 收到的留言
 * @author chenhuiyan
 *
 */
@Controller
@RequestMapping(value = "/toMy")
public class RMessageController {
	
	@Autowired
	private CshtMessageService cshtMessageService;

	/**
	 * 个人中心－收到的留言页面
	 * @param model
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/rMessage")
	public String rMessage(ModelMap model,HttpServletRequest request) throws Exception{
		CshtUser cshtUser = (CshtUser) request.getSession().getAttribute("loginUser");
		Map<String, Integer> res = new HashMap<String, Integer>();
		res.put("userId", cshtUser.getUserId());
		res.put("offset", SystemContext.getOffset());
		res.put("messagePageSize", SystemContext.getMessagePageSize());
		PagerModel<CshtMessageVo> pagerModel = cshtMessageService.getMessageByUserId(res);
		model.addAttribute("pagerModel", pagerModel);
		return "/toMy/rMessage";
	}
	
	/**
	 * 根据留言id查询留言
	 * @param messageId
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "/getMessageByMessageId")
	public Map<String, CshtMessageVo> getMessageByMessageId(@RequestParam(name = "messageId")Integer messageId) 
			throws Exception{
		Map<String, CshtMessageVo> res = new HashMap<String, CshtMessageVo>();
		CshtMessageVo cshtMessageVo = cshtMessageService.getMessageByMessageId(messageId);
		res.put("cshtMessageVo", cshtMessageVo);
		return res;
	}
}
